import numpy as np

# Step 1: Load a NumPy array (example: from a .npy file)
# Replace 'your_array.npy' with your actual file path
array = np.load('1Dflame_60NH3_ULFS_stage4.npy')

# Step 2: Generate random noise based on the original array's values
# Create random noise
random_noise = np.sin(2 * np.pi * np.random.rand(*array.shape))

# Scale the noise by the absolute value of the original array
scaled_noise = 0.01 * np.abs(array) * random_noise

# Step 3: Apply the noise to the original array
# Initialize modified array
modified_array = np.copy(array)

# Apply the noise: 
# For elements == 0, only apply positive noise
for i in range(array.shape[0]):
    for j in range(array.shape[1]):
        if array[i, j] == 0:
            # Only apply positive noise for zero elements
            modified_array[i, j] += max(0, scaled_noise[i, j])
        else:
            # Apply the scaled noise for non-zero elements
            modified_array[i, j] += scaled_noise[i, j]

# Step 4: Output the result (print or save)
print("Original Array:")
print(array)
print("\nModified Array with Noise:")
print(modified_array.shape)

print(np.min(modified_array, axis=0))

# Optional: Save the modified array
# np.save('modified_array.npy', modified_array)